import 'package:flutter/material.dart';
import 'package:shenling_logistics/components/FuncComp.dart';
import 'package:shenling_logistics/utils/Auth.dart';

class SettingPage extends StatelessWidget {
  const SettingPage({super.key});

  Future<void> exitDialog(BuildContext context) async {
    return showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
              content: const Text(
                '确定要退出登录？',
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 16, height: 55 / 16),
              ),
              actions: [
                TextButton(
                    onPressed: () {
                      Navigator.pop(context);
                    },
                    child: Text(
                      '取消',
                      style: TextStyle(
                        fontSize: 16,
                        color: Colors.grey,
                      ),
                    )),
                TextButton(
                    onPressed: () {
                      exit(context);
                    },
                    child: const Text(
                      '退出',
                      style: TextStyle(
                        color: Colors.red,
                        fontSize: 16,
                      ),
                    ))
              ]);
        });
  }

  // 退出登录
  void exit(BuildContext context) {
    // print('退出登录...');
    // 清除用户身份信息
    Auth().clearToken();
    Navigator.pushNamedAndRemoveUntil(context, '/login', (route) => false);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        title: const Text(
          '系统设置',
          style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
        ),
        centerTitle: true,
        leading: IconButton(
          icon: Icon(
            Icons.chevron_left_rounded,
          ), // 你可以替换为任何你喜欢的图标
          onPressed: () {
            Navigator.pop(context); // 返回上一页
          },
        ),
      ),
      body: Container(
          padding: EdgeInsets.only(left: 15, top: 20, right: 15),
          color: Colors.grey[200],
          child: Column(
            children: [
              Container(
                padding: EdgeInsets.only(left: 17.5, right: 12.5),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(8)),
                child: Column(
                  children: [
                    FuncComp(label: '换绑手机'),
                    FuncComp(label: '修改密码'),
                    FuncComp(label: '消息通知设置'),
                    FuncComp(label: '修改密码'),
                    FuncComp(label: '清理缓存'),
                  ],
                ),
              ),
              Container(
                  margin: EdgeInsets.only(top: 40),
                  height: 60,
                  width: MediaQuery.of(context).size.width,
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(8),
                  ),
                  child: GestureDetector(
                    onTap: () {
                      // TODO : 退出登录
                      exitDialog(context);
                    },
                    child: Text(
                      '退出',
                      textAlign: TextAlign.center,
                      style: TextStyle(
                          height: 60 / 16,
                          fontSize: 16,
                          fontWeight: FontWeight.w400),
                    ),
                  ))
            ],
          )),
    );
  }
}
